import 'package:flutter/material.dart';

class CategoryPage extends StatefulWidget {
  @override
  _CategoryPageState createState() => _CategoryPageState();
}

class _CategoryPageState extends State<CategoryPage> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 7,
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.orange,
          title: Row(
            children: <Widget>[
              Expanded(
                child: TabBar(
                  isScrollable: true,
                  labelColor: Colors.blue,
                  unselectedLabelColor: Colors.white,
                  indicatorSize: TabBarIndicatorSize.label,//下划线宽度根据label文字长度自动设置
                  tabs: <Widget>[
                    Text('热销1'),
                    Text('热销2'),
                    Text('热销3'),
                    Text('热销44444'),
                    Text('热销5'),
                    Text('热销6'),
                    Text('热销7'),
                  ],
                ),
              )
            ],
          ),
        ),
        body: TabBarView(
          children: <Widget>[
            ListView(
              children: <Widget>[
                ListTile(
                  title: Text('第1个Tab'),
                ),
                ListTile(
                  title: Text('第1个Tab'),
                ),
              ],
            ),
            ListView(
              children: <Widget>[
                ListTile(
                  title: Text('第2个Tab'),
                ),
                ListTile(
                  title: Text('第2个Tab'),
                )
              ],
            ),
            ListView(
              children: <Widget>[
                ListTile(
                  title: Text('第3个Tab'),
                ),
                ListTile(
                  title: Text('第3个Tab'),
                )
              ],
            ),
            ListView(
              children: <Widget>[
                ListTile(
                  title: Text('第4个Tab'),
                ),
                ListTile(
                  title: Text('第4个Tab'),
                )
              ],
            ),
            ListView(
              children: <Widget>[
                ListTile(
                  title: Text('第5个Tab'),
                ),
                ListTile(
                  title: Text('第5个Tab'),
                )
              ],
            ),
            ListView(
              children: <Widget>[
                ListTile(
                  title: Text('第6个Tab'),
                ),
                ListTile(
                  title: Text('第6个Tab'),
                )
              ],
            ),
            ListView(
              children: <Widget>[
                ListTile(
                  title: Text('第7个Tab'),
                ),
                ListTile(
                  title: Text('第7个Tab'),
                )
              ],
            )
          ],
        ),
      ),
    );
  }
}
